using System;
using System.Collections.Generic;
using System.Text;
using Google.GData.Calendar;
using Google.GData.Client;
using Google.GData.Extensions;

namespace PocketGCal
{
    /// <summary>
    /// Static google calendar container
    /// </summary>
    class GoogleCalendar
    {
        private static List<GFeed> feeds;

        internal static List<GFeed> Feeds
        {
            get {
                if (feeds == null)
                {
                    EventFeed calFeeds = GoogleCalendar.Service.Query(new FeedQuery("http://www.google.com/calendar/feeds/" + GoogleCalendar.UserName));
                    feeds = new List<GFeed>();
                    foreach (AtomEntry feedItem in calFeeds.Entries)
                    {
                        GFeed myFeed = new GFeed();
                        myFeed.FeedName = feedItem.Title.Text;
                        myFeed.FeedUrl = feedItem.SelfUri.Content;
                        feeds.Add(myFeed);
                    }
                }
                return feeds;
            }
        }
        private static string userAgent = "PocketGCal";

        public static Uri Uri
        {
            get { return new Uri("http://www.google.com/calendar/feeds/default/private/full"); }
        }

        private static CalendarService service;

        /// <summary>
        /// Google CalendarService object
        /// </summary>
        public static CalendarService Service
        {
            get {

                if (service == null)
                {
                    service = new CalendarService(userAgent);
                }
                service.setUserCredentials(userName, password);
                //service.RequestFactory = new PocketGCal.GDataRequestFactory(userAgent);
                return service;
            }
        }
        private static string userName;
        /// <summary>
        /// Username to connect to Google
        /// </summary>
        public static string UserName
        {
            get { return GoogleCalendar.userName; }
            set { GoogleCalendar.userName = value; }
        }
        private static string password;
        /// <summary>
        /// Password to connect to Google
        /// </summary>
        public static string Password
        {
            get { return GoogleCalendar.password; }
            set { GoogleCalendar.password = value; }
        }
    }
}
